﻿using System;
using System.Data;
using System.Web.UI.WebControls;

namespace BONSAI.Admin.UC
{
    public partial class ToursUpdate : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                /*BindDropLoadDiemDi();
                BindDropLoadLoaiTours();
                BindDropLoadDiemDen();
                BindLoad();*/
            }
        }
        
        
        public void BindDropLoadLoaiTours()
        {
            /*ListItem list = new ListItem("Tất cả", "0");
            var table = (new LoaiToursBO()).GetAll();

            foreach (var dto in table)
            {
                dropLoaiTours.Items.Add(
                    new ListItem(
                        "(" + dto.ID + ")" + dto.LoaiTours + "(" + dto.LoaiToursEN + ")",
                        dto.ID.ToString()));
            }

            dropLoaiTours.Items.Insert(0, list);*/
        }
        /*
        public void BindLoad()
        {
            if (Request.QueryString["id"] != null)
            {
                DataTable table = tours.Tours_Get(Int32.Parse(Request.QueryString["id"].ToString()));
                if (table.Rows.Count > 0)
                {
                    dropLoaiTours.SelectedValue = table.Rows[0]["TypeTourID"].ToString();
                    dropdiemden.SelectedValue = table.Rows[0]["DiemDenID"].ToString();
                    dropdiemdi.SelectedValue = table.Rows[0]["DiemKhoiHanhID"].ToString();
                    txttentoursTV.Text = table.Rows[0]["TenChuongTrinh"].ToString();
                    txttentoursEN.Text = table.Rows[0]["TenChuongTrinhEN"].ToString();
                    txttenchuongtrinhtomtatVN.Text = table.Rows[0]["TenChuongTrinhTomTat"].ToString();
                    txttenchuongtrinhtomtatEN.Text = table.Rows[0]["TenChuongTrinhTomTatEN"].ToString();
                    txtdiadiemTV.Text = table.Rows[0]["Noichon"].ToString();
                    txtdiadiemEN.Text = table.Rows[0]["NoiChonEN"].ToString();
                    txtsongaydemVN.Text = table.Rows[0]["SoNgayDem"].ToString();
                    txtsongaydemEN.Text = table.Rows[0]["SoNgayDemEN"].ToString();
                    txtGiatoursVN.Text = table.Rows[0]["GiaTours"].ToString();
                    txtGiaToursEN.Text = table.Rows[0]["GiaToursEN"].ToString();
                    txtngaykhoihanh.Text = table.Rows[0]["NgayKhoiHanh"].ToString();
                    txttourscodes.Text = table.Rows[0]["TourCode"].ToString();
                    fcknoidunggioithieuVN.Value = table.Rows[0]["TongQuan"].ToString();
                    fcknoidunggioithieuEN.Value = table.Rows[0]["TongQuanEN"].ToString();
                    fckchitietTV.Value = table.Rows[0]["ChiTiet"].ToString();
                    fckchitietEN.Value = table.Rows[0]["ChiTietEN"].ToString();


                    if (table.Rows[0]["Avatar"].ToString() != "isnull")
                    {
                        Image1.ImageUrl = "~/AdminPhoto/tours1/" + table.Rows[0]["Avatar"].ToString();
                        Session["imgThubnail"] = table.Rows[0]["Avatar"].ToString();
                    }
                }
            }
        }
        protected void btcapnhat_Click(object sender, EventArgs e)
        {
            #region check value
            if (dropLoaiTours.SelectedValue.ToString() == "0")
            {
                WebMBox.Show("Vui lòng chọn loại tours.");
                return;
            }

            // gia tours
            if (txtGiatoursVN.Text == "")
            {
                WebMBox.Show("Vui lòng nhập giá tours Tiếng Việt.");
                return;
            }
            if (txtGiaToursEN.Text == "")
            {
                WebMBox.Show("Vui lòng nhập giá tours Tiếng Anh.");
                return;
            }
            #endregion

            #region check Image 1

            string strAvatar = "isnull";
            if (FileUpload1.HasFile)
            {
                bool fileOK = false;
                String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
                String[] allowedExtensions = { ".jpg", ".bmp", ".png", ".tjf", ".gif" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                    if (fileExtension == allowedExtensions[i])
                        fileOK = true;

                if (fileOK)
                {
                    strAvatar = FileUpload1.FileName;
                    FileUpload1.SaveAs(Server.MapPath("~/AdminPhoto/tours1/") + FileUpload1.FileName);
                }
            }
            else
            {

                strAvatar = string.Empty;

                if (Request.QueryString["id"] == null)
                {
                    WebMBox.Show("Vui lòng chọn ảnh đại điện.");
                    //return;
                }
                else
                {
                    if (Session["imgThubnail"] != null)
                    {
                        strAvatar = Session["imgThubnail"].ToString();
                    }
                }
            }

            #endregion

            //===================

            string str = BONSAIUtils.StrSort(txtngaykhoihanh.Text.Trim());
            //=====================
            if (Request.QueryString["id"] != null)// edit
            {
                tours.Tours_Update(Int32.Parse(Request.QueryString["id"].ToString()), txtdiadiemTV.Text, txtsongaydemVN.Text, txtdiadiemEN.Text, txtsongaydemEN.Text,
                     txttourscodes.Text, txtngaykhoihanh.Text, txttentoursTV.Text, txttentoursEN.Text, txttenchuongtrinhtomtatVN.Text,
                     txttenchuongtrinhtomtatEN.Text, fcknoidunggioithieuVN.Value, fcknoidunggioithieuEN.Value,
                     fckchitietTV.Value, fckchitietEN.Value,
                     decimal.Parse(txtGiatoursVN.Text), decimal.Parse(txtGiaToursEN.Text), Int32.Parse(dropLoaiTours.SelectedValue.ToString())
                     , Int32.Parse(dropdiemdi.SelectedValue.ToString()), Int32.Parse(dropdiemden.SelectedValue.ToString()), strAvatar,Convert.ToDateTime(BONSAIUtils.StrSort(txtngaykhoihanh.Text)));
                Response.Redirect("ToursManager.aspx");
            }
            else // create new
            {
                tours.Tours_Insert(txtdiadiemTV.Text, txtsongaydemVN.Text, txtdiadiemEN.Text, txtsongaydemEN.Text,
                    txttourscodes.Text, txtngaykhoihanh.Text, txttentoursTV.Text, txttentoursEN.Text, txttenchuongtrinhtomtatVN.Text,
                    txttenchuongtrinhtomtatEN.Text, fcknoidunggioithieuVN.Value, fcknoidunggioithieuEN.Value,
                    fckchitietTV.Value, fckchitietEN.Value, 
                    decimal.Parse(txtGiatoursVN.Text), decimal.Parse(txtGiaToursEN.Text),Int32.Parse(dropLoaiTours.SelectedValue.ToString())
                    , Int32.Parse(dropdiemdi.SelectedValue.ToString()), Int32.Parse(dropdiemden.SelectedValue.ToString()), strAvatar, Convert.ToDateTime(BONSAIUtils.StrSort(txtngaykhoihanh.Text)));
                   Response.Redirect("ToursManager.aspx");
            }
        }

        protected void dropLoaiTours_SelectedIndexChanged(object sender, EventArgs e)
        {
            //BindDropLoadDiemDen();
        }

        */
    }
}